
let { addBanner,searchBanner,updateBanner,deleteBanner} = require("../dao/bannerDao");
let { moveFiles, deleteFiles } = require("../utils/handFiles");
module.exports.addBanner = async function (data) {
    let res = await addBanner(data);

    if (res._id) {
        moveFiles({
            fromPath: "./public/temp",
            toPath: "./public/images",
            filename: data.img,
        });
        deleteFiles(`./public/temp/${data.img}`);
        return {
            code: 1,
            msg: "操作成功!",
        };
    }
    // console.log(res)
    return {
        code: 0,
        msg: "操作失败",
    };
};
module.exports.searchBanner = async function (data) {
    let res = await searchBanner(data);
    if (res.result.length) {
        return {
            code: 1,
            data: res,
            msg: "操作成功!",
        };
    }
    return {
        code: 1,
        data: res,
        msg: "操作失败!",
    };
};

module.exports.updateBanner=async function(data){
    let res=await updateBanner(data)
    if(res.modifiedCount===1){
        return {
            code:1,
            msg:"操作成功!"
        }
    }
    return {
        code:0,
        msg:"操作失败!"
    }
}
module.exports.deleteBanner=async function(data){
    let res=await deleteBanner(data)
    if(res.deletedCount===1){
        return {
            code:1,
            msg:"操作成功!"
        }
    }
    return {
        code:0,
        msg:"操作失败!"
    }
}